package com.raccoonagents.tools.cascet2d.model.components;

import java.util.ArrayList;
import java.util.List;

import com.raccoonagents.tools.cascet2d.interfaces.IActionListener;
import com.raccoonagents.tools.cascet2d.interfaces.rendering.IRenderableObject;
import com.raccoonagents.tools.cascet2d.model.Vector2f;
import com.raccoonagents.tools.cascet2d.model.events.ActionEvent;
import com.raccoonagents.tools.cascet2d.util.FWLogger;

public abstract class AbstractStageUIComponent extends AbstractStageComponent implements IRenderableObject{

	protected List<IActionListener> listeners = new ArrayList<IActionListener>();
	private boolean enabled;
	protected Vector2f pivot = new Vector2f(0.0f,0.0f);
	
	public final void addActionlistener(final IActionListener listener){
		if(listeners.contains(listener)){
			FWLogger.warning("attempted to add same listener twice!");
			return;
		}
		listeners.add(listener);
	}
	
	public void removeActionListener(final IActionListener listener){
		listeners.remove(listener);
	}
	
	
	
	public final void notifyListeners(final Object message){
		final ActionEvent e = new ActionEvent(this, message);
		for(final IActionListener listener : listeners){
			listener.actionPerformed(e);
		}
	}

	public void setEnabled(final boolean enabled) {
		this.enabled = enabled;
	}

	public boolean isEnabled() {
		return enabled;
	}
	
	@Override
	public Vector2f getPivot() {
		return pivot;
	}
}
